﻿using System;
using System.IO;

namespace NumericalSolution {
  class Poisson2DFEMMain {

    static String outfile = "c:/nsworkspace/poisson2dfem.txt";

    public static void Main() {

      Poisson2DFEM problem = new Poisson2DFEM();
      problem.NumberOfElements = 20;
      problem.NumberOfNodesInAnElement = 4;
      problem.NumericalIntegration = new GaussLagrange(2);

      problem.CreateMesh();
      problem.AssembleMatrix();
      Node[] node = problem.Solve();

      StreamWriter writer = File.CreateText(outfile);
      for (int i = 0; i < node.Length; i++) {
        if (i != 0 && i % problem.NumberOfNodes == 0) {
          writer.WriteLine();
        }

        writer.Write(node[i].X + " ");
        writer.Write(node[i].Y + " ");
        writer.WriteLine(node[i].Value);
      }
      writer.Close();
    }

  }
}
